<template>
  <div class="container">
    <span class="title">书法家</span>
    <span style="float:right; cursor: pointer;">查看更多...</span>
    <div class="leftArrow" v-if="showLeft">
      <img src="./img/arrow_left.svg" @click="arrowClick('left')" />
    </div>
    <el-carousel height="300px" indicator-position="none" :autoplay=false :loop=false arrow="never" ref='cardShow'>
      <el-carousel-item v-for="(items, index) in artistList" :key="index">
        <div class="f_box">
          <div class="box" v-for="(i, index) in items" :key="index">
            <!-- 王羲之 -->
            <img :src="i.imgUrl" alt="" @click="toDetails(i.title)">
            <div class="name">{{i.title}}</div>
          </div>
        </div>
      </el-carousel-item>
    </el-carousel>
    <div class="rightArrow" v-if="showRight">
      <img src="./img/arrow_right.svg" @click="arrowClick('right')"/>
    </div>
  </div>
</template>

<script>
import { findBanner } from '@/api/home.js'
import Message from '@/components/library/Message'
import { useRouter } from 'vue-router'
import { ref } from 'vue'
// import { useStore } from 'vuex'
export default {
  name: 'HomeArtist',
  setup () {
    const router = useRouter()
    // const store = useStore()
    const showLeft = ref(false)
    const showRight = ref(true)
    const cardShow = ref(null)
    const artistList = ref([])
    function arrowClick (val) {
      if (val === 'right') {
        showRight.value = false
        showLeft.value = true
        cardShow.value.next()
      } else {
        showLeft.value = false
        showRight.value = true
        cardShow.value.prev()
      }
    }
    function toLogin () {
      router.push({ path: '/login' })
    }
    function toDetails (title) {
      // store.commit('user/setNote', imgurl)
      // sessionStorage.setItem('note', imgurl)
      // router.push({ path: '/details', query: { url: imgurl } })
      router.push({ path: '/artistList', query: { title: title } })
    }
    findBanner().then(res => {
      // console.log(res.data)
      // token失效重新登录
      if (res.code === '999') {
        Message({ type: 'error', text: res.msg })
        toLogin()
      }
      if (res.code === '200')artistList.value = res.data[2].artistList || []
    }).catch(err => {
      console.log(err)
    })
    return { showLeft, showRight, cardShow, arrowClick, artistList, toDetails }
  }

}
</script>

<style lang="less" scoped>
.container{
  margin-bottom: 10px;
  margin-top: 50px;
  .title{
    color: rgba(0,0,0,.65);
    font-weight: 600;
    font-size: 20px;
    font-family: PingFangSC-Semibold,PingFang SC;
  }
  .leftArrow{
    width: 50px;
    height: 50px;
    position: absolute;
    margin: 130px 0 0 -25px;
    z-index: 1000;
    opacity: 1;
    border-radius: 100%;
    box-shadow: 0 1px 7px rgb(0 0 0 / 65%);
  }
  .rightArrow{
    width: 50px;
    height: 50px;
    position: absolute;
    margin: -180px 0 500px 1215px;
    z-index: 1000;
    opacity: 1;
    border-radius: 100%;
    box-shadow: 0 1px 7px rgb(0 0 0 / 65%);
  }
}
.f_box{
  height: 100%;
  width: 1240px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  .box{
    height: 70%;
    width: 18%;
    background-color: pink;
    border-radius: 10%;
    .hoverShadow();
    img{
      width: 100%;
      height: 100%;
      border-radius: 10%;
      object-fit: cover;
    }
    .name{
      margin-top: 10px;
      margin-left: 90px;
      color: rgba(0,0,0,.65);
      font-weight: 800;
      font-size: 16px;
    }
  }
}

</style>
